﻿using System;

namespace BrettM.Helpers
{
    public static class DateTimeExtensions
    {
        /// <summary>
        /// Rounds the date to the closest second, ignoring the milliseconds.
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime RoundToSecond(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
        }

        /// <summary>
        /// Rounds the date and time to the closest minute, ignoring the seconds
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime RoundToMinute(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0);
        }

        /// <summary>
        /// Rounds the date and time to the date portion only.
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime RoundToDay(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day);
        }
    }
}
